{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### API\n",
    "\n",
    "\n",
    "#### What is API\n",
    "\n",
    "API stands for **Application Programming Interface**. An API is a software intermediary that allows two applications to talk to each other.  In other words, an API is the messenger that delivers your request to the provider that you’re requesting it from and then delivers the response back to you.\n",
    "\n",
    "#### How do APIs work?\n",
    "Imagine a waiter in a restaurant.  You, the customer, are sitting at the table with a menu of choices to order from, and the kitchen is the provider who will fulfill your order.\n",
    "\n",
    "You need a link to communicate your order to the kitchen and then to deliver your food back to your table. It can’t be the chef because she’s cooking in the kitchen. You need something to connect the customer who’s ordering food and the chef who prepares it.  That’s where the **waiter** — or the **API** —  enters the picture.\n",
    "\n",
    "The waiter takes your order, delivers it to the kitchen, telling the kitchen what to do. It then delivers the response, in this case, the food, back to you. Moreover, if the API is designed correctly, hopefully, your order won’t crash!\n",
    "\n",
    "#### A real example of an API\n",
    "\n",
    "How are APIs used in the real world? Here’s a very common scenario of the API economy at work: booking a flight.\n",
    "\n",
    "When you search for flights online, you have a menu of options to choose from. You choose a departure city and date, a return city and date, cabin class, and other variables like your meal, your seat, or baggage requests.\n",
    "\n",
    "To book your flight, you need to interact with the airline’s website to access the airline’s database to see if any seats are available on those dates, and what the cost might be based on the date, flight time, route popularity, etc.\n",
    "\n",
    "You need access to that information from the airline’s database, whether you’re interacting with it from the website or an online travel service that aggregates information from multiple airlines. Alternatively, you might be accessing the information from a mobile phone. In any case, you need to get the information, and so the application must interact with the airline’s API, giving it access to the airline’s data.\n",
    "\n",
    "**APIs provide a standard way of accessing any application data, or device**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### List of API \n",
    "\n",
    "- Pandas_datareader\n",
    "- Fixer.io\n",
    "- 阿凡达云数据\n",
    "- Tushare"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pandas_datareader\n",
    "\n",
    "#### Install \n",
    "pip install pandas-datareader\n",
    "\n",
    "#### Data Readers\n",
    "- AlphaVantage\n",
    "- Federal Reserve Economic Data (FRED)\n",
    "- Fama-French Data (Ken French’s Data Library)\n",
    "- Bank of Canada\n",
    "- Econdb\n",
    "- Enigma\n",
    "- Eurostat\n",
    "- The Investors Exchange (IEX)\n",
    "- Moscow Exchange (MOEX)\n",
    "- NASDAQ\n",
    "- Naver Finance\n",
    "- Organisation for Economic Co-operation and Development (OECD)\n",
    "- Quandl\n",
    "- Stooq.com\n",
    "- Tiingo\n",
    "- Thrift Savings Plan (TSP)\n",
    "- World Bank\n",
    "\n",
    "You may not be able to use all datasets. \n",
    "\n",
    "Please refer to its Github Repo for more details: [link here](https://pandas-datareader.readthedocs.io/en/latest/readers/index.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Data from FRED St.Louis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GS10</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DATE</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-12-01</th>\n",
       "      <td>2.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-01</th>\n",
       "      <td>2.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-01</th>\n",
       "      <td>2.86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-03-01</th>\n",
       "      <td>2.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-04-01</th>\n",
       "      <td>2.87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            GS10\n",
       "DATE            \n",
       "2017-12-01  2.40\n",
       "2018-01-01  2.58\n",
       "2018-02-01  2.86\n",
       "2018-03-01  2.84\n",
       "2018-04-01  2.87"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas_datareader as pdr\n",
    "pd = pdr.get_data_fred('GS10')\n",
    "pd.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GDP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DATE</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-07-01</th>\n",
       "      <td>23550.420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-01</th>\n",
       "      <td>24349.121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-01-01</th>\n",
       "      <td>24740.480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-01</th>\n",
       "      <td>25248.476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>25663.289</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  GDP\n",
       "DATE                 \n",
       "2021-07-01  23550.420\n",
       "2021-10-01  24349.121\n",
       "2022-01-01  24740.480\n",
       "2022-04-01  25248.476\n",
       "2022-07-01  25663.289"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas_datareader.data as web\n",
    "import datetime\n",
    "start = datetime.datetime(2021,1,1)\n",
    "end = datetime.datetime(2022,11,1)\n",
    "gdp = web.DataReader('GDP', 'fred', start, end)\n",
    "gdp.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Data from Yahoo  🚫"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get data from Yahoo\n",
    "# 使用雅虎财经的话，语句是这样的，但是2021.11.1起暂停服务了\n",
    "import pandas_datareader.data as web\n",
    "import datetime\n",
    "start = datetime.datetime(2019, 1, 1) # or start = '1/1/2016'\n",
    "end = datetime.date.today()\n",
    "prices = web.DataReader('AAPL', 'nasdaq', start, end)\n",
    "prices.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 有用的命令 requests\n",
    "\n",
    "The requests module allows you to send HTTP requests using Python.\n",
    "\n",
    "The HTTP request returns a `Response Object` with all the response data (content, encoding, status, etc).\n",
    "\n",
    "\n",
    "Detail: https://www.w3schools.com/python/module_requests.asp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### JSON\n",
    "\n",
    "JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式。它基于 ECMAScript (欧洲计算机协会制定的js规范)的一个子集，采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。 易于人阅读和编写，同时也易于机器解析和生成，并有效地提升网络传输效率。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Fixer.io  🚫\n",
    "\n",
    "Powered by 15+ exchange rate data sources, the Fixer API is capable of delivering real-time exchange rate data for 170 world currencies. The API comes with multiple endpoints, each serving a different use case. Endpoint functionalities include getting the latest exchange rate data for all or a specific set of currencies, converting amounts from one currency to another, retrieving Time-Series data for one or multiple currencies and querying the API for daily fluctuation data.\n",
    "\n",
    "https://fixer.io/quickstart\n",
    "\n",
    "You need to sign in and get an access key to kick off "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_fixer_hist(date, symbols = 'USD,AUD,CAD,CNY,CHF,GBP,HKD'):\n",
    "    import requests\n",
    "    import json\n",
    "    # get the data from Fixer.io the \n",
    "    # You need to sign in to obtain a free access_key \n",
    "    access_key = '0287efab831449699ce8333ec5307d00'\n",
    "    root_url = 'http://data.fixer.io/api/'\n",
    "    # Make the URL\n",
    "    url = root_url + date +'?'+ 'access_key='+ access_key + '&symbols=' + symbols + '&format=1'\n",
    "    # Creat a header\n",
    "    headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16'}\n",
    "    # request data from API\n",
    "    res = requests.get(url, headers = headers)\n",
    "    # Get content, in case of Chinese we need to encode\n",
    "    content = res.text\n",
    "    # Load JSON data\n",
    "    dcon = json.loads(content)\n",
    "    return dcon['date'], dcon['rates'], url\n",
    "\n",
    "dat = input('Please input a date with a proper format YYYY-MM-DD:')\n",
    "date, rates, url = get_fixer_hist(dat)\n",
    "print('Exchange Rate on {}:'.format(date))\n",
    "for key,values in rates.items():\n",
    "    print('1 '+ key +' = '+ str(values) +' EUR')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  Econdb.com \n",
    "\n",
    "https://www.econdb.com/home/\n",
    "\n",
    "Inflation, industrial production, exports, imports, retail sales and gross domestic product by country"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import pandas as pd\n",
    "from urllib.request import urlopen\n",
    "\n",
    "\n",
    "url = 'https://www.econdb.com/api/series/CPIUS/?format=json'\n",
    "\n",
    "# store the response of URL\n",
    "response = urlopen(url)\n",
    "  \n",
    "# storing the JSON response \n",
    "# from url in data\n",
    "data_json = json.loads(response.read())\n",
    "\n",
    "df = pd.DataFrame.from_dict(data_json['data'])\n",
    "df.head()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 百度智能云 API 商城\n",
    "https://apis.baidu.com/\n",
    "\n",
    "获取AppCode后根据参数要求来获取信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"status\":0,\"msg\":\"ok\",\"result\":[{\"cityid\":1,\"parentid\":0,\"citycode\":\"101010100\",\"city\":\"北京\"},{\"cityid\":2,\"parentid\":0,\"citycode\":null,\"city\":\"安徽\"},{\"cityid\":3,\"parentid\":0,\"citycode\":null,\"city\":\"福建\"},{\"cityid\":4,\"parentid\":0,\"citycode\":null,\"city\":\"甘肃\"},{\"cityid\":5,\"parentid\":0,\"citycode\":null,\"city\":\"广东\"},{\"cityid\":6,\"parentid\":0,\"citycode\":null,\"city\":\"广西\"},{\"cityid\":7,\"parentid\":0,\"citycode\":null,\"city\":\"贵州\"},{\"cityid\":8,\"parentid\":0,\"citycode\":null,\"city\":\"海南\"},{\"cityid\":9,\"parentid\":0,\"citycode\":null,\"city\":\"河北\"},{\"cityid\":10,\"parentid\":0,\"citycode\":null,\"city\":\"河南\"},{\"cityid\":11,\"parentid\":0,\"citycode\":null,\"city\":\"黑龙江\"},{\"cityid\":12,\"parentid\":0,\"citycode\":null,\"city\":\"湖北\"},{\"cityid\":13,\"parentid\":0,\"citycode\":null,\"city\":\"湖南\"},{\"cityid\":14,\"parentid\":0,\"citycode\":null,\"city\":\"吉林\"},{\"cityid\":15,\"parentid\":0,\"citycode\":null,\"city\":\"江苏\"},{\"cityid\":16,\"parentid\":0,\"citycode\":null,\"city\":\"江西\"},{\"cityid\":17,\"parentid\":0,\"citycode\":null,\"city\":\"辽宁\"},{\"cityid\":18,\"parentid\":0,\"cityco\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "# 全国天气预报_获取城市 Python示例代码\n",
    "if __name__ == '__main__':\n",
    "    url = 'http://jisuweather.api.bdymkt.com/weather/city'\n",
    "    \n",
    "    \n",
    "    headers = {\n",
    "        \n",
    "        'Content-Type': 'application/json;charset=UTF-8',\n",
    "        'X-Bce-Signature': 'AppCode/0ffc4030414a428cbea69a96722fa7' # bd\n",
    "    }\n",
    "    r = requests.request(\"GET\", url, headers=headers)\n",
    "    print(r.content.decode('UTF-8')[:1000])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"update_time\":\"2022-11-07 20:28:01\",\"list\":[{\"pm\":1,\"aqi\":142,\"aqi_level\":\"轻度\",\"city\":\"襄阳\",\"province\":\"湖北\"},{\"pm\":2,\"aqi\":132,\"aqi_level\":\"轻度\",\"city\":\"周口\",\"province\":\"河南\"},{\"pm\":3,\"aqi\":130,\"aqi_level\":\"轻度\",\"city\":\"南阳\",\"province\":\"河南\"},{\"pm\":4,\"aqi\":124,\"aqi_level\":\"轻度\",\"city\":\"漯河\",\"province\":\"河南\"},{\"pm\":5,\"aqi\":123,\"aqi_level\":\"轻度\",\"city\":\"驻马店\",\"province\":\"河南\"},{\"pm\":6,\"aqi\":115,\"aqi_level\":\"轻度\",\"city\":\"和田\",\"province\":\"新疆\"},{\"pm\":7,\"aqi\":115,\"aqi_level\":\"轻度\",\"city\":\"商丘\",\"province\":\"河南\"},{\"pm\":8,\"aqi\":115,\"aqi_level\":\"轻度\",\"city\":\"昆玉\",\"province\":\"新疆\"},{\"pm\":9,\"aqi\":108,\"aqi_level\":\"轻度\",\"city\":\"平顶山\",\"province\":\"河南\"},{\"pm\":10,\"aqi\":107,\"aqi_level\":\"轻度\",\"city\":\"高雄\",\"province\":\"台湾\"},{\"pm\":11,\"aqi\":107,\"aqi_level\":\"轻度\",\"city\":\"枣庄\",\"province\":\"山东\"},{\"pm\":12,\"aqi\":104,\"aqi_level\":\"轻度\",\"city\":\"信阳\",\"province\":\"河南\"},{\"pm\":13,\"aqi\":99,\"aqi_level\":\"良\",\"city\":\"荆门\",\"province\":\"湖北\"},{\"pm\":14,\"aqi\":95,\"aqi_level\":\"良\",\"city\":\"三门峡\",\"province\":\"河南\"},{\"pm\":15,\"aqi\":91,\"aqi_level\":\"良\",\"city\":\"亳州\",\"province\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "# 国内空气质量排行 Python示例代码\n",
    "if __name__ == '__main__':\n",
    "    url = 'http://gwgp-h4bqkmub7dg.n.bdcloudapi.com/rankcity'\n",
    "    params = {}\n",
    "    params['order'] = ''\n",
    "    params['callback'] = ''\n",
    "    \n",
    "    \n",
    "    headers = {\n",
    "        \n",
    "        'Content-Type': 'application/json;charset=UTF-8',\n",
    "        'X-Bce-Signature': 'AppCode/0ffc4030414a428cbea69a96722fa7' # bd\n",
    "    }\n",
    "    r = requests.request(\"GET\", url, params=params, headers=headers)\n",
    "    print(r.content.decode('raw_unicode_escape')[:1000])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "共青城市\n"
     ]
    }
   ],
   "source": [
    "# 快递查询  https://apis.baidu.com/store/detail/a37095b1-e249-4e1b-8215-a15b3f40dca6 \n",
    "\n",
    "if __name__ == '__main__':\n",
    "    url = 'http://gwgp-65bmfhhrext.n.bdcloudapi.com/express/query'\n",
    "    params = {}\n",
    "    params['type'] = '' # 快递公司 自动识别请写auto\n",
    "    params['number'] = '' # 快递单号\n",
    "    params['mobile'] = '' # 收件人/寄件人手机号\n",
    "    \n",
    "    \n",
    "    headers = {\n",
    "        \n",
    "        'Content-Type': 'application/json;charset=UTF-8',\n",
    "        'X-Bce-Signature': 'AppCode/您的AppCode'\n",
    "    }\n",
    "    r = requests.request(\"POST\", url, params=params, headers=headers)\n",
    "    print(r.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"msg\":\"成功\",\"success\":true,\"code\":200,\"data\":{\"result\":0,\"order_no\":\"695776469557164789\",\"desc\":\"一致\",\"sex\":\"男\",\"birthday\":\"19781029\",\"address\":\"浙江省杭州市下城区\"}}\n"
     ]
    }
   ],
   "source": [
    "# 身份证实名核验普惠版 Python示例代码\n",
    "if __name__ == '__main__':\n",
    "    url = 'http://gwgp-fsr6ymryhk6.n.bdcloudapi.com/idcard_check_inclusive/get'\n",
    "    params = {}\n",
    "    params['idcard'] = '330103197810290015'\n",
    "    params['name'] = '倪禾'\n",
    "    \n",
    "    \n",
    "    headers = {\n",
    "        \n",
    "        'Content-Type': 'application/json;charset=UTF-8',\n",
    "        'X-Bce-Signature': 'AppCode/0ffc4030414a428cbea69a96722fa7' # bd\n",
    "    }\n",
    "    r = requests.request(\"GET\", url, params=params, headers=headers)\n",
    "    print(r.content.decode('UTF-8'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 阿凡达云数据平台  🚫\n",
    "\n",
    "http://api.avatardata.cn/ActNews/Query?key=3c901762cd104a2793df344b6015ff00&keyword="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 目前不可用\n",
    "def avatardata(keyword):\n",
    "    import requests\n",
    "    import json\n",
    "    \n",
    "    access_key = '3c901762cd104a2793df344b6015ff00'\n",
    "    root_url = 'http://api.avatardata.cn/ActNews/Query?'\n",
    "    url = root_url + 'key=' + access_key + '&keyword=' + keyword\n",
    "    headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16'}\n",
    "    # request data from API\n",
    "    res = requests.get(url, headers = headers)\n",
    "    # Get content, in case of Chinese we need to encode\n",
    "    content = res.text\n",
    "    # Load JSON data\n",
    "    dcon = json.loads(content)\n",
    "    return dcon['result'], url\n",
    "\n",
    "keyword = input('想听谁的八卦:')\n",
    "res, url = avatardata(keyword)\n",
    "\n",
    "for r in res:\n",
    "    print(r['full_title'] +'  '+ r['pdate_src'] ) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Tushare\n",
    "\n",
    "tushare.pro \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>shortname</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>address</th>\n",
       "      <th>phone</th>\n",
       "      <th>office</th>\n",
       "      <th>website</th>\n",
       "      <th>chairman</th>\n",
       "      <th>manager</th>\n",
       "      <th>reg_capital</th>\n",
       "      <th>setup_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>employees</th>\n",
       "      <th>main_business</th>\n",
       "      <th>org_code</th>\n",
       "      <th>credit_code</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>北京广能投资基金管理有限公司</td>\n",
       "      <td>广能基金</td>\n",
       "      <td>北京</td>\n",
       "      <td>北京市</td>\n",
       "      <td>北京市朝阳区北四环中路27号院5号楼2712-2715A</td>\n",
       "      <td>None</td>\n",
       "      <td>北京市朝阳区北四环中路27号院5号楼2712-2715A</td>\n",
       "      <td>www.gnfund.cn</td>\n",
       "      <td>刘锡潜</td>\n",
       "      <td>杨运成</td>\n",
       "      <td>10000.0000</td>\n",
       "      <td>20111031</td>\n",
       "      <td>None</td>\n",
       "      <td>10.0</td>\n",
       "      <td>None</td>\n",
       "      <td>584419680</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>宏源证券股份有限公司</td>\n",
       "      <td>宏源证券</td>\n",
       "      <td>新疆</td>\n",
       "      <td>乌鲁木齐市</td>\n",
       "      <td>新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦</td>\n",
       "      <td>86-991-2301870</td>\n",
       "      <td>新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦</td>\n",
       "      <td>www.hysec.com</td>\n",
       "      <td>冯戎</td>\n",
       "      <td>冯戎</td>\n",
       "      <td>397240.8332</td>\n",
       "      <td>19930525</td>\n",
       "      <td>None</td>\n",
       "      <td>5347.0</td>\n",
       "      <td>主要业务:代理买卖证券.</td>\n",
       "      <td>228593068</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>国元证券股份有限公司</td>\n",
       "      <td>国元证券</td>\n",
       "      <td>安徽</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>安徽省合肥市梅山路18号</td>\n",
       "      <td>86-551-62207323,86-551-62207968</td>\n",
       "      <td>安徽省合肥市梅山路18号</td>\n",
       "      <td>www.gyzq.com.cn</td>\n",
       "      <td>蔡咏</td>\n",
       "      <td>俞仕新</td>\n",
       "      <td>336544.7047</td>\n",
       "      <td>19970606</td>\n",
       "      <td>None</td>\n",
       "      <td>3330.0</td>\n",
       "      <td>主营业务:经纪业务,自营投资业务,投行业务,资产管理业务,基金管理业务,期货业务,境外业务国...</td>\n",
       "      <td>731686376</td>\n",
       "      <td>91340000731686376P</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广发证券股份有限公司</td>\n",
       "      <td>广发证券</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广东省广州市黄埔区中新广州知识城腾飞一街2号618室</td>\n",
       "      <td>86-20-87555888,86-20-87550565,86-20-87550265</td>\n",
       "      <td>广东省广州市天河区天河北路183-187号大都会广场40楼5楼,7楼,8楼,18楼,19楼,...</td>\n",
       "      <td>www.gf.com.cn</td>\n",
       "      <td>孙树明</td>\n",
       "      <td>林治海</td>\n",
       "      <td>762108.7664</td>\n",
       "      <td>19940121</td>\n",
       "      <td>None</td>\n",
       "      <td>12103.0</td>\n",
       "      <td>主营业务:证券经纪</td>\n",
       "      <td>126335439</td>\n",
       "      <td>91440000126335439C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>长江证券股份有限公司</td>\n",
       "      <td>长江证券</td>\n",
       "      <td>湖北</td>\n",
       "      <td>武汉市</td>\n",
       "      <td>湖北省武汉市江汉区新华路特8号</td>\n",
       "      <td>86-27-65799866,86-27-65799856</td>\n",
       "      <td>湖北省武汉市江汉区新华路特8号</td>\n",
       "      <td>www.cjsc.com</td>\n",
       "      <td>尤习贵</td>\n",
       "      <td>刘元瑞</td>\n",
       "      <td>552947.0960</td>\n",
       "      <td>19970724</td>\n",
       "      <td>None</td>\n",
       "      <td>6637.0</td>\n",
       "      <td>主营业务:证券经纪</td>\n",
       "      <td>700821272</td>\n",
       "      <td>91420000700821272A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             name shortname province   city                       address  \\\n",
       "0  北京广能投资基金管理有限公司      广能基金       北京    北京市  北京市朝阳区北四环中路27号院5号楼2712-2715A   \n",
       "1      宏源证券股份有限公司      宏源证券       新疆  乌鲁木齐市      新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦   \n",
       "2      国元证券股份有限公司      国元证券       安徽    合肥市                  安徽省合肥市梅山路18号   \n",
       "3      广发证券股份有限公司      广发证券       广东    广州市    广东省广州市黄埔区中新广州知识城腾飞一街2号618室   \n",
       "4      长江证券股份有限公司      长江证券       湖北    武汉市               湖北省武汉市江汉区新华路特8号   \n",
       "\n",
       "                                          phone  \\\n",
       "0                                          None   \n",
       "1                                86-991-2301870   \n",
       "2               86-551-62207323,86-551-62207968   \n",
       "3  86-20-87555888,86-20-87550565,86-20-87550265   \n",
       "4                 86-27-65799866,86-27-65799856   \n",
       "\n",
       "                                              office          website  \\\n",
       "0                       北京市朝阳区北四环中路27号院5号楼2712-2715A    www.gnfund.cn   \n",
       "1                           新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦    www.hysec.com   \n",
       "2                                       安徽省合肥市梅山路18号  www.gyzq.com.cn   \n",
       "3  广东省广州市天河区天河北路183-187号大都会广场40楼5楼,7楼,8楼,18楼,19楼,...    www.gf.com.cn   \n",
       "4                                    湖北省武汉市江汉区新华路特8号     www.cjsc.com   \n",
       "\n",
       "  chairman manager  reg_capital setup_date end_date  employees  \\\n",
       "0      刘锡潜     杨运成   10000.0000   20111031     None       10.0   \n",
       "1       冯戎      冯戎  397240.8332   19930525     None     5347.0   \n",
       "2       蔡咏     俞仕新  336544.7047   19970606     None     3330.0   \n",
       "3      孙树明     林治海  762108.7664   19940121     None    12103.0   \n",
       "4      尤习贵     刘元瑞  552947.0960   19970724     None     6637.0   \n",
       "\n",
       "                                       main_business   org_code  \\\n",
       "0                                               None  584419680   \n",
       "1                                       主要业务:代理买卖证券.  228593068   \n",
       "2  主营业务:经纪业务,自营投资业务,投行业务,资产管理业务,基金管理业务,期货业务,境外业务国...  731686376   \n",
       "3                                          主营业务:证券经纪  126335439   \n",
       "4                                          主营业务:证券经纪  700821272   \n",
       "\n",
       "          credit_code  \n",
       "0                None  \n",
       "1                None  \n",
       "2  91340000731686376P  \n",
       "3  91440000126335439C  \n",
       "4  91420000700821272A  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tushare as ts\n",
    "import getpass\n",
    "\n",
    "tushare_token = getpass.getpass('Please input the token: ')  # 请在 tushare.pro 网站注册并且告知学生身份，可以取得你的token\n",
    "pro = ts.pro_api(tushare_token)\n",
    "\n",
    "\n",
    "df = pro.fund_company()\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>chairman</th>\n",
       "      <th>manager</th>\n",
       "      <th>secretary</th>\n",
       "      <th>setup_date</th>\n",
       "      <th>province</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>300459.SZ</td>\n",
       "      <td>朱志刚</td>\n",
       "      <td>张维璋</td>\n",
       "      <td>胡斐</td>\n",
       "      <td>20070612</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>300615.SZ</td>\n",
       "      <td>石伟平</td>\n",
       "      <td>石伟平</td>\n",
       "      <td>孙海龙</td>\n",
       "      <td>20050510</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>300309.SZ</td>\n",
       "      <td>张鹏辉</td>\n",
       "      <td>郭明杰</td>\n",
       "      <td>付大鹏</td>\n",
       "      <td>20060515</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>300341.SZ</td>\n",
       "      <td>杨文良</td>\n",
       "      <td>杨泽声</td>\n",
       "      <td>李臻</td>\n",
       "      <td>20021104</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>300591.SZ</td>\n",
       "      <td>林大耀</td>\n",
       "      <td>林大耀</td>\n",
       "      <td>苏继祥</td>\n",
       "      <td>20020419</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code chairman manager secretary setup_date province\n",
       "0  300459.SZ      朱志刚     张维璋        胡斐   20070612       浙江\n",
       "1  300615.SZ      石伟平     石伟平       孙海龙   20050510       广东\n",
       "2  300309.SZ      张鹏辉     郭明杰       付大鹏   20060515       北京\n",
       "3  300341.SZ      杨文良     杨泽声        李臻   20021104       福建\n",
       "4  300591.SZ      林大耀     林大耀       苏继祥   20020419       广东"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.stock_company(exchange='SZSE', fields='ts_code,chairman,manager,secretary,setup_date,province')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>publish_date</th>\n",
       "      <th>country</th>\n",
       "      <th>confirmed_num</th>\n",
       "      <th>update_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>272</th>\n",
       "      <td>20200203</td>\n",
       "      <td>美国</td>\n",
       "      <td>9</td>\n",
       "      <td>2020-02-03 09:28:34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>20200202</td>\n",
       "      <td>美国</td>\n",
       "      <td>8</td>\n",
       "      <td>2020-02-02 07:41:43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>20200201</td>\n",
       "      <td>美国</td>\n",
       "      <td>6</td>\n",
       "      <td>2020-02-01 02:48:13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>20200131</td>\n",
       "      <td>美国</td>\n",
       "      <td>6</td>\n",
       "      <td>2020-01-31 07:17:36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>20200127</td>\n",
       "      <td>美国</td>\n",
       "      <td>5</td>\n",
       "      <td>2020-01-27 17:20:43</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    publish_date country  confirmed_num          update_time\n",
       "272     20200203      美国              9  2020-02-03 09:28:34\n",
       "273     20200202      美国              8  2020-02-02 07:41:43\n",
       "274     20200201      美国              6  2020-02-01 02:48:13\n",
       "275     20200131      美国              6  2020-01-31 07:17:36\n",
       "276     20200127      美国              5  2020-01-27 17:20:43"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.ncov_global(country='美国', fields='country,publish_date,confirmed_num,update_time')\n",
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>title</th>\n",
       "      <th>content</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20221105</td>\n",
       "      <td>习近平在第五届中国国际进口博览会开幕式上发表致辞</td>\n",
       "      <td>11月4日晚，国家主席习近平以视频方式出席在上海举行的第五届中国国际进口博览会开幕式并发表题...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20221105</td>\n",
       "      <td>【央视快评】让开放为全球发展带来新的光明前程</td>\n",
       "      <td>本台今天（11月5日）播发央视快评《让开放为全球发展带来新的光明前程》。</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20221105</td>\n",
       "      <td>习近平在《湿地公约》第十四届缔约方大会开幕式上发表致辞</td>\n",
       "      <td>11月5日下午，国家主席习近平以视频方式出席在武汉举行的《湿地公约》第十四届缔约方大会开幕式...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20221105</td>\n",
       "      <td>李克强与德国总理共同会见中德经济界代表并座谈交流</td>\n",
       "      <td>国务院总理李克强4日晚在京与德国总理朔尔茨共同会见中德经济界代表并座谈交流，两国近30位企业...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20221105</td>\n",
       "      <td>李强出席第五届中国国际进口博览会开幕式</td>\n",
       "      <td>中共中央政治局常委李强4日在上海出席第五届中国国际进口博览会开幕式。李强指出，习近平主席发表...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       date                        title  \\\n",
       "0  20221105     习近平在第五届中国国际进口博览会开幕式上发表致辞   \n",
       "1  20221105       【央视快评】让开放为全球发展带来新的光明前程   \n",
       "2  20221105  习近平在《湿地公约》第十四届缔约方大会开幕式上发表致辞   \n",
       "3  20221105     李克强与德国总理共同会见中德经济界代表并座谈交流   \n",
       "4  20221105          李强出席第五届中国国际进口博览会开幕式   \n",
       "\n",
       "                                             content  \n",
       "0  11月4日晚，国家主席习近平以视频方式出席在上海举行的第五届中国国际进口博览会开幕式并发表题...  \n",
       "1               本台今天（11月5日）播发央视快评《让开放为全球发展带来新的光明前程》。  \n",
       "2  11月5日下午，国家主席习近平以视频方式出席在武汉举行的《湿地公约》第十四届缔约方大会开幕式...  \n",
       "3  国务院总理李克强4日晚在京与德国总理朔尔茨共同会见中德经济界代表并座谈交流，两国近30位企业...  \n",
       "4  中共中央政治局常委李强4日在上海出席第五届中国国际进口博览会开幕式。李强指出，习近平主席发表...  "
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.cctv_news(date='20221105')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20221104</td>\n",
       "      <td>10.40</td>\n",
       "      <td>10.85</td>\n",
       "      <td>10.39</td>\n",
       "      <td>10.82</td>\n",
       "      <td>10.44</td>\n",
       "      <td>0.38</td>\n",
       "      <td>3.6398</td>\n",
       "      <td>1776112.23</td>\n",
       "      <td>1903720.944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20221103</td>\n",
       "      <td>10.54</td>\n",
       "      <td>10.57</td>\n",
       "      <td>10.38</td>\n",
       "      <td>10.44</td>\n",
       "      <td>10.63</td>\n",
       "      <td>-0.19</td>\n",
       "      <td>-1.7874</td>\n",
       "      <td>983535.61</td>\n",
       "      <td>1028904.286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20221102</td>\n",
       "      <td>10.61</td>\n",
       "      <td>10.68</td>\n",
       "      <td>10.48</td>\n",
       "      <td>10.63</td>\n",
       "      <td>10.67</td>\n",
       "      <td>-0.04</td>\n",
       "      <td>-0.3749</td>\n",
       "      <td>1302988.18</td>\n",
       "      <td>1377816.220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20221101</td>\n",
       "      <td>10.38</td>\n",
       "      <td>10.68</td>\n",
       "      <td>10.36</td>\n",
       "      <td>10.67</td>\n",
       "      <td>10.34</td>\n",
       "      <td>0.33</td>\n",
       "      <td>3.1915</td>\n",
       "      <td>1381234.13</td>\n",
       "      <td>1459758.367</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20221031</td>\n",
       "      <td>10.33</td>\n",
       "      <td>10.45</td>\n",
       "      <td>10.22</td>\n",
       "      <td>10.34</td>\n",
       "      <td>10.42</td>\n",
       "      <td>-0.08</td>\n",
       "      <td>-0.7678</td>\n",
       "      <td>983095.69</td>\n",
       "      <td>1016230.012</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code trade_date   open   high    low  close  pre_close  change  \\\n",
       "0  000001.SZ   20221104  10.40  10.85  10.39  10.82      10.44    0.38   \n",
       "1  000001.SZ   20221103  10.54  10.57  10.38  10.44      10.63   -0.19   \n",
       "2  000001.SZ   20221102  10.61  10.68  10.48  10.63      10.67   -0.04   \n",
       "3  000001.SZ   20221101  10.38  10.68  10.36  10.67      10.34    0.33   \n",
       "4  000001.SZ   20221031  10.33  10.45  10.22  10.34      10.42   -0.08   \n",
       "\n",
       "   pct_chg         vol       amount  \n",
       "0   3.6398  1776112.23  1903720.944  \n",
       "1  -1.7874   983535.61  1028904.286  \n",
       "2  -0.3749  1302988.18  1377816.220  \n",
       "3   3.1915  1381234.13  1459758.367  \n",
       "4  -0.7678   983095.69  1016230.012  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.daily(ts_code='000001.SZ', start_date='20200701', end_date='20221105')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>industry</th>\n",
       "      <th>list_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>19910403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>全国地产</td>\n",
       "      <td>19910129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>ST国华</td>\n",
       "      <td>深圳</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>19910114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>19901210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "      <td>深振业A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>区域地产</td>\n",
       "      <td>19920427</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code  symbol  name area industry list_date\n",
       "0  000001.SZ  000001  平安银行   深圳       银行  19910403\n",
       "1  000002.SZ  000002   万科A   深圳     全国地产  19910129\n",
       "2  000004.SZ  000004  ST国华   深圳     软件服务  19910114\n",
       "3  000005.SZ  000005  ST星源   深圳     环境保护  19901210\n",
       "4  000006.SZ  000006  深振业A   深圳     区域地产  19920427"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pro.query('stock_basic', exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     ts_code  symbol  name area industry market list_date\n",
      "0  000007.SZ  000007   全新好   深圳     其他商业     主板  19920413\n",
      "1  000008.SZ  000008  神州高铁   北京     运输设备     主板  19920507\n",
      "2  000009.SZ  000009  中国宝安   深圳     电气设备     主板  19910625\n",
      "3  000010.SZ  000010  美丽生态   深圳     建筑工程     主板  19951027\n",
      "4  000011.SZ  000011  深物业A   深圳     区域地产     主板  19920330\n",
      "5  000012.SZ  000012   南玻A   深圳       玻璃     主板  19920228\n",
      "6  000014.SZ  000014  沙河股份   深圳     全国地产     主板  19920602\n",
      "7  000016.SZ  000016  深康佳A   深圳     家用电器     主板  19920327\n",
      "8  000017.SZ  000017  深中华A   深圳       服饰     主板  19920331\n",
      "9  000019.SZ  000019  深粮控股   深圳     农业综合     主板  19921012\n"
     ]
    }
   ],
   "source": [
    "# 导入tushare\n",
    "import tushare as ts\n",
    "# 初始化pro接口\n",
    "pro = ts.pro_api('1c8b06446534ae510c8c68e38fc248b99f89ac3814cb55645ae2be72')\n",
    "\n",
    "# 拉取数据\n",
    "df = pro.stock_basic(**{\n",
    "    \"ts_code\": \"\",\n",
    "    \"name\": \"\",\n",
    "    \"exchange\": \"\",\n",
    "    \"market\": \"\",\n",
    "    \"is_hs\": \"\",\n",
    "    \"list_status\": \"\",\n",
    "    \"limit\": 10,\n",
    "    \"offset\": 5\n",
    "}, fields=[\n",
    "    \"ts_code\",\n",
    "    \"symbol\",\n",
    "    \"name\",\n",
    "    \"area\",\n",
    "    \"industry\",\n",
    "    \"market\",\n",
    "    \"list_date\"\n",
    "])\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Homework\n",
    "\n",
    "1. 取得10家市值最大的**银行行业**的上市公司从去年年初至今的股票的日行情数据，并将该数据存入MySQL数据库\n",
    "\n",
    "2. 动量效应指的是指股票的收益率有延续原来的运动方向的趋势，即过去一段时间收益率较高的股票在未来获得的收益率仍会高于过去收益率较低的股票。请用调用数据去验证，如随机寻找部分的涨停股票，考察其涨停后几日的发展趋势，并和其他股票进行对比。\n",
    "\n",
    "3. 有人说持有低市值股票可以获利，请试试是否正确。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### OECD\n",
    "\n",
    "https://stats.oecd.org/\n",
    "\n",
    "The OECD has application programming interfaces (APIs) that provide access to datasets in the catalogue of OECD databases.\n",
    "\n",
    "Please see the instruction of API as follows\n",
    "\n",
    "https://data.oecd.org/api/sdmx-json-documentation/\n",
    "\n",
    "你是否可以取到其中的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6 (default, Aug  5 2022, 15:21:02) \n[Clang 14.0.0 (clang-1400.0.29.102)]"
  },
  "vscode": {
   "interpreter": {
    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
